<!--suppress ALL -->
<template>
    <div class="withdrawal-records">
        <div class="top-box">
            <el-form :model="query" ref="form" inline>
                <el-form-item prop="name">
                    <el-input v-model="query.name" placeholder="请输入提现人" style="width: 200px"></el-input>
                </el-form-item>
                <el-form-item prop="time">
                    <el-date-picker
                        v-model="query.time"
                        type="daterange"
                        align="right"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        value-format="yyyy-MM-dd"
                    >

                    </el-date-picker>
                </el-form-item>
            </el-form>

            <div class="btns-container">
                <el-button type="primary" @click="getTableData">
                    查询
                </el-button>
                <el-button @click="reset">
                    重置
                </el-button>
                <el-button @click="goToWithdrawal">
                    前往提现
                </el-button>
            </div>
        </div>

        <el-table :data="tableData" border style="width: 100%">
            <el-table-column prop="transferBillNo" label="转账单id" width="120"></el-table-column>
            <el-table-column prop="userName" label="提现人" width="120"></el-table-column>
            <el-table-column prop="amount" label="提现金额" width="120">
                <template #default="scope">
                    <span>{{ scope.row.amount }}元</span>
                </template>
            </el-table-column>
            <el-table-column label="提现方式" width="120">
                <template>
                    微信
                </template>
            </el-table-column>
            <el-table-column prop="bankInfo" label="银行卡信息" width="200"></el-table-column>
            <!--      <el-table-column label="操作" width="180">-->
            <!--        <template #default="scope">-->
            <!--         -->
            <!--          <el-button size="small" type="primary" @click="handleView(scope.row)">查看</el-button>-->
            <!--        </template>-->
            <!--      </el-table-column>-->

        </el-table>

        <el-pagination
            :current-page="current"
            :page-sizes="[10]"
            :page-size="size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @current-change="handleCurrentChange">
        </el-pagination>
    </div>
</template>

<script>
import {getWithdrawalRecords} from "@/api/distribute";

export default {
    name: "WithdrawalRecords",
    data() {
        return {
            query: {
                time: [],
                name: ""
            },
            tableData: [],
            current: 1,
            size: 10,
            total: 100,
            dialogVisible: false,
            editForm: {
                withdrawer: "",
                withdrawalAmount: 0,
                withdrawalMethod: "",
                wechat: "",
                alipay: "",
                bankInfo: ""
            },
            currentIndex: -1
        };
    },
    created() {
        this.getTableData();
    },
    methods: {
        getTableData() {
            getWithdrawalRecords({
                current: this.current,
                size: this.size,
                name: this.query.name,
                startTime: this.query.time[0] || null,
                endTime: this.query.time[1] || null
            }).then(res => {
                this.total = res.total;
                this.tableData = res.records;
            })
        },
        handleCurrentChange(val) {
            this.current = val;
            // 根据新的current重新获取数据
            this.getTableData();
        },
        goToWithdrawal() {
            this.$router.push({
                path: "/distribution/distributionDetail",
                params: {
                    id: 1
                }
            });
        },
        reset() {
            this.$refs.form.resetFields();
            this.getTableData();
        }
    }
};
</script>

<style scoped lang="scss">
.withdrawal-records {
    padding: 20px;
}

.btns-container {
    display: flex;
    gap: 16px;
}
.top-box{
    margin-bottom: 16px;
    background: white;
    padding: 16px 0;
    border-radius: 4px;
}
</style>
